package com.game.majiang.vo;

import java.sql.Types;
import java.util.ArrayList;

import javax.sql.rowset.CachedRowSet;

import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;
import com.game.server.db.entity.AccountTixian;

public class AccountTixianVo {

	public static void insertInto(int uid, int gold, int accounttype, String account, 
			String accountname, String openingbank, String phone) {
		String sql = "INSERT INTO accounttixian (uid,gold,accounttype,account,accountname,openingbank,phone,"
				+ "state,createtime) "
				+ "VALUES (?,?,?,?,?,?,?,0,now())";
		Parameter p1 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, gold, ParameterType.Input);
		Parameter p3 = new Parameter(Types.INTEGER, accounttype, ParameterType.Input);
		Parameter p4 = new Parameter(Types.VARCHAR, account, ParameterType.Input);
		Parameter p5 = new Parameter(Types.VARCHAR, accountname, ParameterType.Input);
		Parameter p6 = new Parameter(Types.VARCHAR, openingbank, ParameterType.Input);
		Parameter p7 = new Parameter(Types.VARCHAR, phone, ParameterType.Input);
		
		SqlHelperwrite.execute(sql, p1,p2,p3,p4,p5,p6,p7);
		
	}
	
	public static ArrayList<AccountTixian> selectUser(int uid) {
		ArrayList<AccountTixian> listTixian = new ArrayList<>();
		String sql = "SELECT id,uid,gold,accounttype,account,accountname,openingbank,"
				+ "phone,state,createtime,shenhetime FROM accounttixian WHERE uid = ? "
				+ "ORDER BY createtime DESC";
		Parameter p1 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		CachedRowSet resultSet = SqlHelper.getResultSet(sql, p1);
		try {
			while (resultSet.next()) {
				AccountTixian at = new AccountTixian();
				at.id = resultSet.getInt("id");
				at.uid = resultSet.getInt("uid");
				at.gold = resultSet.getInt("gold");
				at.accounttype = resultSet.getInt("accounttype");
				at.account = resultSet.getString("account");
				at.accountname = resultSet.getString("accountname");
				at.openingbank = resultSet.getString("openingbank");
				at.phone = resultSet.getString("phone");
				at.state = resultSet.getInt("state");
				at.createtime = resultSet.getString("createtime");
				at.shenhetime = resultSet.getString("shenhetime");
				listTixian.add(at);
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return listTixian;
	}
	
	
}
